using System;
using System.Collections.Generic;
using System.Text;

namespace Lu62Viewer
{
    class MyRootNode : MyNode
    {
        private char m_selectedTerminator;
        private char m_selectedSeparator;
        private int m_selectedSegmentNameLenght;

        private const string rootNodeText = "root";

        public MyRootNode(string _lu62string, char _terminator, char _separator, int _nameLenght)
        {
            Text = rootNodeText;            
            m_selectedSeparator = _separator;
            m_selectedTerminator = _terminator;
            m_selectedSegmentNameLenght = _nameLenght;
            Lenght = _lu62string.Length;            
            populateTreeNodes(_lu62string);
        }

        private void populateTreeNodes(string _luText)
        {
            int currentPos = 1;
            int startPos = 0;
            string segmentText = string.Empty;                     
            foreach (char _c in _luText)
            {
                if (_c == m_selectedTerminator)
                {                    
                    segmentText = _luText.Substring(startPos, currentPos - startPos);
                    Nodes.Add(new MySegmentNode(segmentText, m_selectedSeparator, m_selectedSegmentNameLenght, startPos));
                    startPos = currentPos;
                }
                currentPos++;
            }            
        }        
    }
}
